What does the ready() function do in jQuery? Explain it by giving suitable example.
ready() function do in jQuery with suitable example.
247
28-Jul-2021
Aryan Kumar
27-Nov-2023In jQuery, the $(document).ready() function is used to execute code when the DOM (Document Object Model) is fully loaded and ready to be manipulated. It ensures that your jQuery code runs after the HTML document has been parsed and is ready for interaction.
Here's an example to illustrate the use of $(document).ready():
In this example:
Inside the $(document).ready() function, you can include any jQuery code you want to execute once the DOM is ready. This is a good practice to ensure that your code won't run until the HTML document is fully loaded.
It's worth noting that a shorthand for $(document).ready() is $(function() {...}). Both notations are equivalent, and you can use either based on your preference.